<template>
	<view class="add">
		<view class="uni-list">
			<view class="uni-list-cell">
				<view class="uni-list-cell-navigate uni-navigate-right">
					<view>帐号类型</view>
					<picker class="picker-item text-gray" mode="selector" :value="bank_index" range-key="name" :range="banks" @change="typeChange">
						<view>{{banks[bank_index]['name']}}</view>
					</picker>
				</view>
			</view>
			<view class="uni-list-cell">
				<view class="uni-list-cell-navigate">
					<view class="iconfont icon-weibiaoti2fuzhi12"></view>
					<input type="text" placeholder="收款人" v-model="account_name" />
				</view>
			</view>
			<view class="uni-list-cell">
				<view class="uni-list-cell-navigate">
					<view class="iconfont icon-zhanghao"></view>
					<input type="text" placeholder="收款帐号" v-model="account_no" />
				</view>
			</view>
		</view>
		
		<view class="radius-btn" @tap="saveForm()">保存</view>
	</view>
</template>

<script>
	import Request from '../../common/request.js';
	
	export default {
		data() {
			return {
				account_name: '',
				account_no:'',
				banks:[],
				bank_index: 0,
				
			};
		},
		onLoad() {
			this.getBank();
		},
		methods: {
			getBank: function(){
				var that = this;
				Request.send({
					url: 'funds/banks',
					sCallback: function(res) {
						that.banks = res.data;
						
					}
				})
			},
			saveForm:function(){
				if(this.bank_index == null) {
					Request.alert('请选择帐号类型');
					return;
				}


				if(!this.account_name) {
					Request.alert('请填写收款人');
					return;
				}

				if(!this.account_no) {
					Request.alert('请填写收款帐号');
					return;
				}

				var url =  'funds/addAccount';
				var that = this;
				Request.send({
					url: url,
					data: {
						account_name:that.account_name, 
						account_no:that.account_no, 
						bank_id: that.banks[that.bank_index]['id'],
					},
					sCallback: function(res) {
						uni.showToast({
							title: res.msg,
							success() {
								uni.navigateBack({
									
								})
							}
						})
					}
				})
				

			},

			//选择银行
			typeChange: function(e){
				
				
				this.bank_index = e.detail.value;
				this.type_name = this.banks[e.detail.value]['name'];			
					
			}
		}
	}
</script>

<style>
	.add{
		font-size: 28upx;
	}
	
	.add .radius-btn{
		margin-top: 70upx;
	}
	
	.add picker{
		margin-right: 20upx;
	}
	
	.add .iconfont{
		width: 80upx;
		font-size: 40upx;
	}
	
	.add input{
		flex: 1;
	}
</style>
